package PROYECTO2.src.Frames_Minds;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
import java.util.ArrayList;

import javax.swing.JPanel;

import PROYECTO2.src.Game;
import PROYECTO2.src.Explosiones_Disparos.Shot;
import PROYECTO2.src.Naves.Enemigos.Cylon;

public class PanelCylons extends JPanel {

	protected MindCylons mind;
	protected Game game;
	

	public PanelCylons (Game g) {
		mind = new MindCylons(this,g);
		game = g;
		setLayout(null);
        setOpaque(false);
        setBounds(0,0,800, 600);
	}
	
	public synchronized void paint(Graphics g) {
	        super.paint(g);

	        Graphics2D g2d = (Graphics2D) g;
	        
	        ArrayList cylons = mind.getCylons();
	        
	        //repinta los enemigos
	        for (int i = 0; i < cylons.size(); i++ ) {
	            Cylon m = (Cylon) cylons.get(i);
	            AffineTransform tx = m.getRotacion();
	            g2d.setTransform(tx);
	            g2d.drawImage(m.getImage(), m.getX(), m.getY(), this);
	            
	        }
	        
	        ArrayList ms = game.getLaseresCylons();
	        
	        //mueve, repinta y elimina los disparos en caso de que ya no sean visibles
	        for (int j = 0; j < ms.size(); j++ ) {
	            Shot shot = (Shot) ms.get(j);
	            if (shot != null)
		            if(shot.isVisible()) {
		            	shot.move();
		            	AffineTransform tx = AffineTransform.getRotateInstance(0, shot.getX() , shot.getY());
			            g2d.setTransform(tx);
			            g2d.drawImage(shot.getImage(), shot.getX(), shot.getY(), this);
		            } else {
		            	ms.remove(j);
		            }
	            
	        }
	 

	        Toolkit.getDefaultToolkit().sync();
	        g.dispose();
	        
    }
	 
	public MindCylons getMindCylons() {
		 return mind;
	}

}